#include "Matrix.h"
#include <memory.h>
#include <iostream>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;


Mat4::Mat4(void)
{
	memset(&rows,0.0,16);
}


Mat4::~Mat4(void)
{
}

void Mat4::identity()
{
	for (int i = 0 ; i < 4 ; ++i)
	{
		(*this)[i][i] = 1.0;
	}
}
Mat4 Mat4::operator*(Mat4& r)
{
	Mat4 ret;
	for (int row = 0 ; row < 4 ; ++row)
	{
		for (int col = 0 ; col < 4 ; ++col)
		{
			for (int i = 0; i < 4;++i)
			{
				ret[row][col] = (*this)[row][i] + r[i][col];
			}
		}
	}
	return ret;
}
void Mat4::print(){
	cout << "[Matrix Begin]" <<endl;
	for (int row = 0 ; row < 4 ; ++row)
	{
		for (int col = 0 ; col < 4 ; ++col)
		{
			cout << (*this)[row][col];
			if (col < 3)cout << ",";
		}
		if (row < 4)cout << endl;
	}
	cout << "[Matrix end]" <<endl;
}
void Mat4::rotX(float angle){
	identity();
	float arc = angle / 180.0 * M_PI;
	float s = sin(arc), c = cos(arc);
	rows[1][1] = c;
	rows[1][2] = s;
	rows[2][1] = -s;
	rows[2][2] = c;
}
void Mat4::rotY(float angle){
	identity();
	float arc = angle / 180.0 * M_PI;
	float s = sin(arc), c = cos(arc);
	rows[0][0] = c;
	rows[0][2] = s;
	rows[2][0] = -s;
	rows[2][2] = c;
}
void Mat4::rotZ(float angle){
	identity();
	float arc = angle / 180.0 * M_PI;
	float s = sin(arc), c = cos(arc);
	rows[0][0] = c;
	rows[0][1] = s;
	rows[1][0] = -s;
	rows[1][1] = c;
}

void Mat4::translate( float x,float y,float z )
{
	identity();
	rows[3][0] = x;
	rows[3][1] = y;
	rows[3][2] = z;
}

void Mat4::scale( float sx,float sy,float sz )
{
	identity();
	rows[0][0] = sx;
	rows[1][1] = sy;
	rows[2][2] = sz;
	rows[3][3] = 1;
}
